package com.deer.wms.quartz.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.deer.wms.project.root.util.StringUtils;
import com.deer.wms.quartz.constant.ScheduleConstants;
import com.deer.wms.quartz.util.CronUtils;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.util.Date;

/**
 * 定时任务调度表 sys_job
 * 
 * @author deer
 */
@Getter
@Setter
@NoArgsConstructor
public class SysJob implements Serializable
{
    /** 任务ID */
    @TableId(type = IdType.AUTO)
    private Long jobId;
    /** 任务名称 */
    private String jobName;
    /** 任务组名 */
    private String jobGroup;
    /** 任务方法 */
    private String methodName;
    /** 方法参数 */
    private String methodParams;
    /** cron执行表达式 */
    private String cronExpression;
    /** cron计划策略 */
    private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT;
    /** 是否并发执行（0允许 1禁止） */
    private String concurrent;
    /** 任务状态（0正常 1暂停） */
    private String status;
    /** 创建者 */
    private String createBy;
    /**
     * 创建时间
     */
    private String createTime;
    /** 更新者 */
    private String updateBy;
    /**
     * 更新时间
     */
    private String updateTime;
    /** 备注 */
    private String remark;

    public Date getNextValidTime()
    {
        if (StringUtils.isNotEmpty(cronExpression))
        {
            return CronUtils.getNextExecution(cronExpression);
        }
        return null;
    }

    public String getMisfirePolicy()
    {
        return misfirePolicy;
    }


    public SysJob(String jobName, String jobGroup, String methodName, String methodParams, String cronExpression, String misfirePolicy, String concurrent, String status, String remark) {
        this.jobName = jobName;
        this.jobGroup = jobGroup;
        this.methodName = methodName;
        this.methodParams = methodParams;
        this.cronExpression = cronExpression;
        this.misfirePolicy = misfirePolicy;
        this.concurrent = concurrent;
        this.status = status;
        this.remark = remark;
    }
}